package cn.jtool.dig.common.netty;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 流水号生成器
 */
public class SNGenerator {

    private static AtomicInteger snGen = new AtomicInteger(1);

    private final static Integer MAX_SN = 0xFFFF;

    public static synchronized Integer gen(){
        int sn = snGen.incrementAndGet();
        if(sn >= MAX_SN){
            snGen.set(0);
            sn = snGen.incrementAndGet();
        }
        return sn;
    }

}
